package cc.wsyw126.java.nowcoder.interview;

import cc.wsyw126.java.lintCode.convert_binary_search_tree_to_doubly_linked_list.TreeNode;

/**
 * Created by Administrator on 2017/4/27.
 * 是否为二叉搜索树
 */
public class CheckerBST {
    public boolean checkBST(TreeNode root) {
        return doCheckBST(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
    }

    public boolean doCheckBST(TreeNode root, int min, int max) {
        if (root == null) return true;
        if (root.val <=min || root.val >=max) return false;
        return doCheckBST(root.left, min, root.val) && doCheckBST(root.right, root.val, max);
    }
}
